package com.jrtc.backend.controller;

import com.jrtc.base.config.dto.ResultDTO;
import com.jrtc.base.config.dto.ResultDTOBuilder;
import com.jrtc.base.entity.bo.CatchBallRecord;
import com.jrtc.base.entity.bo.FingerFuckRecord;
import com.jrtc.base.entity.vo.FingerFuckRecordVo;
import com.jrtc.service.CatchBallRecordService;
import com.jrtc.service.FingerFuckRecordService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("fingerFuckRecord")
public class FingerFuckRecordController {
    /**
     * 服务对象
     */
    @Resource
    private FingerFuckRecordService fingerFuckRecordService;

    /**
     * 添加患者手指操记录
     * */
    @PostMapping("/insertRecord")
    public ResultDTO insertRecord(@RequestBody FingerFuckRecord fingerFuckRecord){
        FingerFuckRecordVo fingerFuckRecordVo;
        try {
            fingerFuckRecordVo = fingerFuckRecordService.insertRecord(fingerFuckRecord);
        } catch (Exception e){
            return ResultDTOBuilder.failure(e.getMessage());
        }

        return ResultDTOBuilder.success(fingerFuckRecordVo);
    }

    /**
     * 手指操记录图表
     * */
    @PostMapping("/record")
    public ResultDTO record(@RequestBody Map<String, Object> map){
        Integer id = Integer.parseInt(map.get("id").toString());
        FingerFuckRecord fingerFuckRecord = fingerFuckRecordService.record(id);
        return ResultDTOBuilder.success(fingerFuckRecord);
    }
}